package com.etime.shuhuiyuan.controllers.course;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.etime.shuhuiyuan.common.BaseMessage;
import com.etime.shuhuiyuan.common.PageMessage;
import com.etime.shuhuiyuan.common.PojoMessage;
import com.etime.shuhuiyuan.dto.CourseDto;
import com.etime.shuhuiyuan.dto.SalerDto;
import com.etime.shuhuiyuan.pojo.Course;
import com.etime.shuhuiyuan.services.course.interfaces.CourseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "course接口")
@RestController
@RequestMapping("/course")
public class CourseController {
    @Autowired
    private CourseService courseService;


    @ApiOperation("分页查询案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pagenum",value = "第几页"),
            @ApiImplicitParam(name = "pagesize",value = "每页多少行")}
    )
    @GetMapping("/page")
    public PageMessage<CourseDto> selectCourseDtoByPage(CourseDto courseDto, Long pagenum, Long pagesize){
        Page<CourseDto> pagedata = courseService.selectCourseDtoByPage(courseDto,pagenum,pagesize);
        PageMessage<CourseDto> msg = new PageMessage<>();
        //非空判断
        if (pagedata!=null){
            msg.setCode(1);
            msg.setPagedata(pagedata);
        }else{
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("根据courseid查询一条courseDto信息的案例")
    @ApiImplicitParam("courseid")
    @GetMapping("/get/{courseid}")
    public PojoMessage<CourseDto> selectCourseDtoById(@PathVariable("courseid") int courseid){
        CourseDto courseDto = courseService.selectCourseDtoById(courseid);
        PojoMessage<CourseDto> msg = new PojoMessage<>();
        if (courseDto!=null){
            msg.setData(courseDto);
            msg.setCode(1);
        }else {
            msg.setCode(0);
            msg.setMsg("没有查询到数据");
        }
        return msg;
    }

    @ApiOperation("修改案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="courseid",value = "所需要需改的courseid"),
            @ApiImplicitParam(name="coursetypeid",value="课程类型"),
            @ApiImplicitParam(name="coursetitle",value = "课程标题"),
            @ApiImplicitParam(name="coursesubtitle",value="课程副标题"),
            @ApiImplicitParam(name="coursestate",value = "课程状态"),
            @ApiImplicitParam(name="coursegoals",value = "课程目标"),
            @ApiImplicitParam(name="courseaudiences",value = "课程适合人群"),
            @ApiImplicitParam(name="courseprice",value = "课程价格"),
            @ApiImplicitParam(name="courseoriginprice",value = "课程人民币原价"),
            @ApiImplicitParam(name="coursecoinprice",value = "课程虚拟币价格"),
            @ApiImplicitParam(name="coursecoinmaxpoint",value = "最多使用虚拟币数量"),
            @ApiImplicitParam(name="coursecoinused",value = "课程是否开启虚拟币购买"),
            @ApiImplicitParam(name="courserecommended",value = "是否推荐"),
            @ApiImplicitParam(name="courseteachername",value = "课程教师姓名"),
    })
    @PostMapping("/update")
    public PojoMessage<CourseDto> updateCourseDto(CourseDto courseDto){
        PojoMessage<CourseDto> msg = new PojoMessage<>();
        int res = courseService.updateCourseDto(courseDto);
        if (res>0){
            msg.setCode(1);
            msg.setMsg("修改成功");
        }else {
            msg.setCode(0);
            msg.setMsg("修改失败");
        }
        return msg;
    }

    @ApiOperation("插入案例")
    @ApiImplicitParams({
            @ApiImplicitParam(name="coursetypeid",value="课程类型"),
            @ApiImplicitParam(name="coursetitle",value = "课程标题"),
            @ApiImplicitParam(name="coursesubtitle",value="课程副标题"),
            @ApiImplicitParam(name="coursestate",value = "课程状态"),
            @ApiImplicitParam(name="coursegoals",value = "课程目标"),
            @ApiImplicitParam(name="courseaudiences",value = "课程适合人群"),
            @ApiImplicitParam(name="coursepic",value = "课程图片"),
            @ApiImplicitParam(name="courseprice",value = "课程价格"),
            @ApiImplicitParam(name="courseoriginprice",value = "课程人民币原价"),
            @ApiImplicitParam(name="coursecoinprice",value = "课程虚拟币价格"),
            @ApiImplicitParam(name="coursecoinmaxpoint",value = "最多使用虚拟币数量"),
            @ApiImplicitParam(name="coursecoinused",value = "课程是否开启虚拟币购买"),
            @ApiImplicitParam(name="courserecommended",value = "是否推荐"),
            @ApiImplicitParam(name="courseteachername",value = "课程教师姓名")

    })
    @PostMapping("/insert")
    public BaseMessage insertCourseDto(CourseDto courseDto){
        BaseMessage msg = new BaseMessage();
        int res = courseService.insertCourseDto(courseDto);
        msg.setCode(res);
        if (res>0){
            msg.setMsg("插入成功");
        }else {
            msg.setMsg("插入失败");
        }
        return msg;
    }

}
